package com.lwz.eduservice.controller;


import com.lwz.eduservice.entity.EduSubject;
import com.lwz.eduservice.entity.subject.OneSubject;
import com.lwz.eduservice.service.EduSubjectService;
import com.lwz.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.jnlp.ClipboardService;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author Lw中
 * @since 2020-11-10
 */

@Api(value = "课程管理")
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {

    @Autowired
    EduSubjectService eduSubjectService;

    @ApiOperation(value = "导入课程信息excel表")
    @PostMapping("/addSubject")
    public R addSubject(@ApiParam(name = "file", value = "excel文件", required = true)
                                    MultipartFile file) {
        eduSubjectService.addSubject(file, eduSubjectService);
        return R.ok();
    }

    @GetMapping("/getAllSubject")
    public R getAllSubject() {
        // 因为一级分类中包含所有的分类，所以泛型中填入的是OneObject
        List<OneSubject> subjects = eduSubjectService.getAllOneTwoSubject();
        return R.ok().data("list", subjects);
    }

}

